package com.abel.bigwater.data.sanchuan

import com.abel.bigwater.data.BcdString
import io.netty.buffer.Unpooled
import org.junit.Test
import org.slf4j.LoggerFactory

class MeterOfflineTests {
    /**
     * offline-reply bytes: 68 00 0b 68 79 00 10 11 02 03 04 05 36 01 00 df 16
     */
    @Test
    fun testOfflineReply() {
        val p = SanchuanPacket().also {
            it.ctrlb = CtrlbType.OfflineReply
            it.actrlb = 0
            it.meterId = BcdString(byteArrayOf(10, 11, 2, 3, 4, 5, 36, 1), true)

            it.data = MeterOfflineReply(MeterOfflineReply.FIXED_LEN)
        }

        val buf = Unpooled.buffer().also {
            p.fillBuffer(it)
            lgr.info("offline-reply bytes: ${BcdString.create(it, it.readableBytes()).bcdStringBlank()}")
        }
    }

    /**
     * offline bytes: 68 00 0b 68 f9 00 10 11 02 03 04 05 36 01 01 60 16
     */
    @Test
    fun testOffline() {
        val p = SanchuanPacket().also {
            it.ctrlb = CtrlbType.Offline
            it.actrlb = 0
            it.meterId = BcdString(byteArrayOf(10, 11, 2, 3, 4, 5, 36, 1), true)

            it.data = MeterOfflineData(MeterOfflineData.FIXED_LEN).apply { flag = OfflineFlagType.GameOver }
        }

        val buf = Unpooled.buffer().also {
            p.fillBuffer(it)

            lgr.info("offline bytes: ${BcdString.create(it, it.readableBytes()).bcdStringBlank()}")
        }
    }

    companion object {
        private val lgr = LoggerFactory.getLogger(MeterOfflineTests::class.java)
    }
}